package org.example.j1110nm2;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
//下面的这个表示的就是我们的类路径


@Controller
@RequestMapping("/test03")
public class Test03 {

    @RequestMapping("/r1")
    public String r1(){
        return "/test01.html";
    }

    @ResponseBody
    @RequestMapping("/r2")
    public String r2(){
        return "hello html";
    }

    @ResponseBody
    @RequestMapping("/r3")
    public String r3(){
        return "<h1>我是一个html的片段</h1>";
    }

    @ResponseBody
    @RequestMapping("/r4")
    public UserInfo r4(){
        UserInfo userInfo = new UserInfo();
        userInfo.setAge(18);
        userInfo.setId(12);
        userInfo.setName("zhangsan");
        return userInfo;
    }

    @RequestMapping("/r5")
    public String r5(){
        return "/a.js";
    }

    @RequestMapping("/r6")
    public String r6(){
        return "/b.css";
    }

    @ResponseBody
    @RequestMapping("/r7")
    public String r7(HttpServletResponse response){
        response.setStatus(401);
        return "设置状态码成功！！！";
    }

    @ResponseBody
    @RequestMapping(value = "/r8",produces = "application/json;charset=utf-8")
    public String r8(){
        return "{\"ok\":1111}";
    }

    @ResponseBody
    @RequestMapping("/r9")
    public String r9(HttpServletResponse response){
        response.setHeader("myheader","myheadervalue");
        return "自定义header设置成功";
    }
}
